<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<link href="css/redmond/jquery-ui-1.10.3.custom.min.css" rel="stylesheet" type="text/css">	<!-- jquery UI CSS函式庫 -->
<link href="css/jquery-ui-timepicker-addon.css" rel="stylesheet" type="text/css">
<link href="css/selfTemplate.css" rel="stylesheet" type="text/css">							<!-- 自建CSS函式庫 -->
					
<script src="js/jquery-1.10.2.min.js" type="text/javascript"></script>								<!-- jquery 函式庫 -->
<script src="js/jquery-ui-1.10.3.custom.js" type="text/javascript"></script>					<!-- jquery UI 函式庫 -->
<script src="js/jquery.cookie.js" type="text/javascript"></script>								<!-- 操做cookie用 -->
<script src="js/jquery-ui-timepicker-addon.js" type="text/javascript"></script>								<!-- 操做cookie用 -->

<script src="js/widgets.js" type="text/javascript"></script>									<!-- 自建函式庫 -->



<style type="text/css">
	th {
		background: #79B7E7;
		color: white;
		padding-left: 5px;
		padding-right: 5px;
	}

	div#mainDiv {
		width: 45%; 
		padding-top:20px;
		padding-buttom:20px; 
		padding-right:20px;
		padding-left:15px; 
	}

	div#divTabs { vertical-align: text-top; }
</style>

<script type="text/javascript">



$(document).ready(function(){
	
	init("testerDep.html");
	var itemType = $.cookie("itemType");
	var dif = JSON.parse( $.cookie("testDep") );
	var toDoListId = $.cookie("toDoListId");
	
	if ( itemType=='4' ) {
		$("#btnSubmit").button()
			.attr("creatorId",dif.applierId)
			.attr("isDailyBuild",dif.isDailyBuild)
			.attr("modId",dif.modId)
			.attr("jobSN",dif.jobSN)
			.show();
		$("td#actName").html("回覆測試結果");
		document.title = $("td#actName").html();	//頁面的中文名字
		$("tr.itemType3").remove();
	} else {
		$("#btnSubmit").hide();
	}
	
	
	$.removeCookie("testDep");				//儲存模組的基本資料
	$.removeCookie("toDoListId");
	$.removeCookie("itemType");
	
	var subsys = dif.subsysDesc + "(" + dif.subsysId + ")";
	
	$("#subsysId").val( dif.subsysId );
	$("#chkInId").html( dif.chkInId );
	$("#subsys").html( subsys );
	$("#applier").html( dif.applierName );
	$("#cdt").html( dif.cDT );
	$("#fileVer").html( dif.fileVer );		//欲部署的封裝檔版次
	$("#fileName").html( dif.fileName );		//欲部署的封裝檔名
	
	if ( dif.isUrgent =="true" ) {
		$("#isUrgent").addClass("boldRed").html("是");
	} else {
		$("#isUrgent").addClass("boldGreen").html("否");
	}
	var isDailyBuild = "";
	if ( dif.isDailyBuild =="true" ) {
		$("#isDailyBuild").html("是");
		isDailyBuild = "MR";
	} else {
		$("#isDailyBuild").html("否");
		isDailyBuild = "OL";
	}
	var jobName = isDailyBuild+"_"+dif.subsysId+"_"+dif.modId;
	$.each(dif.reqs, function(i,req) {
		var res = 0;
		$.ajax({ type:'post',url:"ChkTestResult",dataType:'text',async:false,
			data: {modId:jobName,jobSN:dif.jobSN,reqId:req.i1,isDailyBuild:dif.isDailyBuild},
			success : function(reses) {
				res = reses;
			}, error : function(xhr, ajaxOptions, thrownError) { errorAjx(xhr); }
		});
		
		if ( itemType=='4' ) {
			tmp = "<td><SELECT reqId='"+req.i1+"'><option value='0'>尚未測試</option><option value='1'>成功</option><option value='2'>失敗</option><option value='3'>無需測試</option></SELECT></td>";
		} else {
			tmp = "<td></td>";
		}
		
		tmp = "<tr class='reqId"+req.i1+"'>"+
		"<td class='idx'>"+(i+1)+"</td>"+
		"<td>"+req.s1+"</td>"+
		tmp+
		"</tr>";
		
		//不同的模組，可能選擇相同的需求，但因都在這次繳交所以不可以重覆計算
		if( $("tr.reqId"+req.i1).size() == 0 ) {
			$("#tbodyReq").append(tmp);
		}
		
		
		$("#tbodyReq select:last").attr("ori",res).val(res);	//將該筆需求改為查到的記錄
	});
	refreshUI(1,"tbodyReq",false);
	
	$("#depTime").datetimepicker({
		timeFormat: 'HH:mm'
	});
	
	$("#btnImmeDep").bind("click", function(){
		$("#diaConfirm").html("真的要立即部署？");
		$("#diaConfirm").css("visibility", "visible").dialog({
			resizable:true,width:300,modUnital:true,show:"fold",hide:"fold",
			buttons : {
				"確定" : function() {
					windowFreeze("部署中...");
					$.ajax({ type:'post',url:"DepTokyo",dataType:'text',async:false,
						data: {dif:JSON.stringify(dif),toDoListId:toDoListId,empId:$.cookie("empId")},
						success : function(res) {
							if( res == "success") {
								alert("部署成功");
								window.location = "toDoList.html";
							}
						}, error : function(xhr, ajaxOptions, thrownError) { errorAjx(xhr); }
					});
					windowUnfreeze();
					$(this).dialog("close");
				},"關閉" :function() {
					$(this).dialog("close");
				}
			}
		});
	});
	
	$("#btnSubmit").bind("click",function(){
		var reqs = [];
		$("#tbodyReq select").each(function(){
			var ori = $(this).attr("ori");
			var reqId = $(this).attr("reqId");
			if ( $(this).val() != ori ) {	//每個 SELECT 去比對，如果和畫面產生時的值不同，就有回傳的必要
				reqs.push({"reqId":reqId,"result":$(this).val()});
			}
		});
		
		var reqTestResult = {reqs:reqs};
		reqTestResult=JSON.stringify(reqTestResult);
		
		$.ajax({ type:'post',url:"CreTestResult",dataType:'text',async:false,
			data: {dif:JSON.stringify(dif),toDoListId:toDoListId,empId:$.cookie("empId"),reqs:reqTestResult},
			success : function(res) {
				alert("更新成功");
				window.location = "toDoList.html";
			}, error : function(xhr, ajaxOptions, thrownError) { errorAjx(xhr); }
		});
	});
	
	$("button").button();
});

</script>
</head>
<body>
	<div id="header"></div>		<!-- 畫面抬頭 -->

	<div id="mainDiv" style="position:relative">
	<div style="position:absolute;padding-left:10px;padding-right:10px;right:0;">
		<div id="divReqs">
			
			<table id="tableReq">
				<thead class="tableFirst">
					<tr><td class="left">相關需求</td><td class="right" colspan="2"><button type="button" id="btnSubmit">送出測試結果</button></td></tr>
					<tr>
						<th>#</th>
						<th>需求描述</th>
						<th></th>
					</tr>
				</thead>
				<tbody id="tbodyReq"></tbody>
			</table>
		</div>
	</div>
	<table>
		<tr><th class="right">繳交代號</th><td id="chkInId"></td></tr>
		<tr><th class="right">子系統</th><td id="subsys"></td></tr>
		<tr><th class="right">繳交人員</th><td id="applier"></td></tr>
		<tr><th class="right">繳交時間</th><td id="cdt"></td></tr>
		<tr><th class="right">緊急上線</th><td id="isUrgent"></td></tr>
		<tr><th class="right">每日建置</th><td id="isDailyBuild"></td></tr>
		<tr><th class="right">部署檔名</th><td id="fileName"></td></tr>
		<tr><th class="right">部署版次</th><td id="fileVer"></td></tr>
		<tr><td colspan="2">&nbsp;</td></tr>
		<tr class='itemType3'><th class="right">預約部署時間</th><td><input class="engN" id="depTime" readonly type="text" size="14" />&nbsp;<button type="button">Go!</button></td></tr>
		<tr class='itemType3'><td colspan="2" class="center">或是</td></tr>
		<tr class='itemType3'><td colspan="2" class="center"><button id="btnImmeDep" type="button">立即部署</button></td></tr>
	</table>
	<input type="hidden" id="subsysId">
</div>
<p>
<p>
</body>

<!-- 單純確認的對話框 -->
<div class="dialog" id="diaConfirm"></div>

</html>